﻿using System.Collections.Generic;

namespace TFSAdministrationTool.Common
{
  public class History
  {
    #region Fields
    private List<HistoryItem> m_History = new List<HistoryItem>();
    private int m_LastIndex = 0;
    #endregion

    #region Methods
    public void AddHistoryItem(string userName, string displayName, ChangeType changeType, string server, string teamProject, SystemTier tier, string role, Status status)
    {
      m_History.Add(new HistoryItem(userName, displayName, changeType, server, teamProject, tier, role, status));
    }

    public void ClearHistory()
    {
      m_History.Clear();
      m_LastIndex = 0;
    }

    public List<HistoryItem> GetNewHistoryItems()
    {
      List<HistoryItem> list = new List<HistoryItem>();

      for (int index = m_LastIndex; index < m_History.Count; index++) {
        list.Add(m_History[index]);
      }
      
      // Update the index
      m_LastIndex = m_History.Count;

      return list;
    }
    #endregion
  } //End History Class

  public class HistoryItem
  {
    #region Fields
    public string UserName { get; private set; }
    public string DisplayName { get; private set; }
    public ChangeType ChangeType { get; private set; }
    public string TeamProject { get; private set; }
    public string Server { get; private set; }
    public SystemTier Tier{ get; private set; }
    public string Role{ get; private set; }
    public Status Status{ get; private set; }
    #endregion

    #region Constructors
    public HistoryItem(string userName, string displayName, ChangeType changeType, string teamProject, string server, SystemTier tier, string role, Status status)
    {
      UserName = userName;
      DisplayName = displayName;
      ChangeType = changeType;
      TeamProject = teamProject;
      Server = server;
      Tier = tier;
      Role = role;
      Status = status;
    }
    #endregion

  } //End HistoryItem Class
} //End Namespace
